/* 复审 */
<template lang="html">
  <Card :bordered="false">
    <p slot="title">复审</p>
    <MyTrialTab :info="info" />
    <table style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th colspan="6">
          初审修改
        </th>
      </tr>
      <tr>
        <td width="16.66%">
          修改人员
        </td>
        <td width="16.66%" class='sizeStyle'>
          {{info.CModifier}}
        </td>
        <td width="16.66%">
          初审时间
        </td>
        <td width="16.66%" class='sizeStyle'>
          {{info.CAtime}}
        </td>
        <td width="16.66%">
          修改完成时间
        </td>
        <td width="16.66%" class='sizeStyle'>
          {{info.CModifiertime}}
        </td>
      </tr>
      <tr>
        <td colspan="6">
          <div style="width:99%;margin:auto;height:100%;">
            <Table border ref="selection" style="border: none" :columns="chushenColumns" :data="info.Chushen" :loading="chushenLoading"></Table>
          </div>
        </td>
      </tr>
    </table>
    <table style="margin-bottom: 20px" width='100%' border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th colspan="4">
          复审单
        </th>
      </tr>
      <tr>
        <td width="25%">
          复审工程师
        </td>
        <td width="25%" class='sizeStyle'>{{info.FAudit}}</td>
        <td width="25%">
          复审时间
        </td>
        <td width="25%" class='sizeStyle'>
          {{this.$moment().format('YYYY-MM-DD')}}
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <div style="width:99%;margin:auto;height:100%;">
            <Table id="fushen" border ref="selection" style="border: none" :columns="fushenColumns" :data="info.Fushen"
              :loading="fushenLoading" @on-row-click="getIndex"></Table>
            <Row>
              <Col span="24" style="text-align: center;padding:10px">
              <Button type="primary" @click="inputAdd('Fushen')">添加</Button>
              <Button type="error" @click="inputRemove('Fushen')">删除</Button>
              </Col>
            </Row>
          </div>
        </td>
      </tr>
      <tr>
        <td>
          报告（正文、附图、附件、附表）
        </td>
        <td colspan="3">
          <!-- <Upload action="//jsonplaceholder.typicode.com/posts/">
            <Button>上传</Button>
          </Upload> -->
          <Button v-if="info.doc!=undefined&&info.doc.ProjectEnvOverview!='undefined'?true:false" :disabled='ProjectEnvOverview!=""?false:true'  :to="ProjectEnvOverview" target='_blank' style="float:left;margin-left:50px">下载</Button>
          <Upload 
          with-credentials 
          :before-upload="upLoadFun" 
          :data='imgUpload' 
          :action="shishi"
          ref="uploadButton"
          >
            <Button>上传</Button>
          </Upload>
        </td>
      </tr>
    </table>
    <Row style="margin-top: 10px">
      <Col span="24" style="text-align:right;">
      <Button type="primary" @click="submit(2)">发送意见</Button>
      </Col>
    </Row>

  </Card>
</template>
<script>
  import libs from "../../../libs/uploads";
  export default {
    data() {
      return {
        shishi:'',
        imgUpload: {
          Id: this.$route.query.ProjectId,
          Key: 'ImgUrl'
        },
        loading: true,
        chushenLoading: true,
        fushenLoading: true,
        query: [],
        info: [],
        chushenColumns: [{
            align: 'center',
            type: 'selection',
            width: 60
          },
          {
            align: 'center',
            title: '序号',
            key: 'num',
            type: 'index',
            width: 80
          },
          {
            align: 'center',
            title: '初审意见',
            key: 'AuditOpinion'
          },
          {
            align: 'center',
            title: '修改说明',
            key: 'ReviseExplain'
          },
        ],
        fushenColumns: [
          // {
          //   align: 'center',
          //   type: 'selection',
          //   width: 60
          // },
          {
            align: 'center',
            title: '序号',
            type: 'index',
            width: 80
          },
          {
            align: 'center',
            title: '复审意见',
            key: 'AuditOpinion',
            render: (h, {
              row,
              index
            }) => {
              return h('Input', {
                props: {
                  type: 'textarea',
                  autosize:true,
                  value: row.AuditOpinion
                },
                on: {
                  'on-blur': (val) => {
                    this.info.Fushen[index].AuditOpinion = val.target.value
                    console.log(val.target.value)
                  }
                }
              })
            }
          },
        ],
        upInfo: {
          fsName: ''
        },
        ProjectEnvOverview:'',
        proType: 0,
        outTime: 0,
      }
    },
    mounted() {
      let query = this.$route.query
      this.query = query
      this.findByProject(query.ProjectId, query.Atype)
      this.shishi = libs.uploads();
    },
    methods: {
      inputAdd(type) {
        // this.info[type].push({})
        this.info[type].push({AuditTime:new Date().getTime()})
      },
      inputRemove(type) {
        this.info[type].splice(this.allIndex, 1);
        console.log(this.info[type] + ' 被删除了')
      },
      getIndex(data, index, event) {
        this.allIndex = index;
      },
      findByProject(ProjectId, Atype) {
        // axios.get('/audit/findByProject', {
        this.$post('audit.findByProject', {
            Atype,
            ProjectId
        }).then(res => {
          this.getDownInfo()
          this.info = res
          this.imgUpload.Name = '复审' + 1 + '批'
          this.chushenLoading = false
          this.fushenLoading = false
          this.upInfo.fsName = this.upWord(res.ReportOriginal)
          console.log(this.info)
          if(res.Stats == '审核中'){
            this.proType = 1
          }
        })
      },
      getDownInfo(){
        axios.post("wechatpublic/findImg",{
          Id:this.$route.query.ProjectId
        }).then((res)=>{
          if(this.info.Stats == '未提交'){
            this.ProjectEnvOverview =''
          }else{
            for(var i=0;i<res.data.length;i++){
              if(res.data[i].Status == '复审'){
                this.ProjectEnvOverview = res.data[i].ImgUrl
              }
            }
          }
        })
      },
      upLoadFun(){
        this.$refs.uploadButton.clearFiles()
        if(this.proType != 1){
          this.$Message.warning('审核未开始，无法上传文件')
          return false
        }
      },
      submit(type) {
        if(this.outTime == 0){
          this.outTime = 1
          var bl = false;
          setTimeout(()=>{this.outTime = 0},5000)
          let query = this.query
          let AuditReplyLists = this.info.Fushen
          AuditReplyLists.map(i=>{
            if(i.AuditOpinion && i.AuditOpinion != ''){
              
            }else{
              bl = true
            }
          })
          if(bl){
            this.outTime = 0
            alert('请填写完整意见后，再发送意见！')
            return
          }
          var dataArr = Object.keys(AuditReplyLists).length <=0 ? [] : '123'
          for (let val of AuditReplyLists) {
            val['AuditId'] = query.Id
            // val['Audit_time'] = this.$moment().format('YYYY-MM-DD HH:mm:ss')
          }
          axios.get('/audit/isAuditb', {
            params: {
              ProjectId: this.$route.query.ProjectId,
              Btype: this.$route.query.Atype,
              OK: 1,
              Save: type,
              AuditReplyLists: dataArr,
            }
          }).then(res => {
            let title = res._MESSAGE
            if (res._STATUS == 1) {
              // if (Object.keys(AuditReplyLists).length <= 0) {
              //   this.$Modal.error({
              //     title: '点击添加请输入意见'
              //   })
              //   return
              // }
              this.$Modal.success({
                title: title 
              })
              social({
                method: 'post',
                url: '/info/notice',
                params: {
                  content: this.info.ProjectName +'项目复审工程师提出审核意见，请尽快进行修改！',
                  app_name: '环评管控系统',
                  app: 'eao',
                  type: this.info.StaffNamesId + '',
                  uid: -1
                },
                }).then((res)=>{
                  console.log(res)
                }).catch((err)=>{
                  console.log(err)
              })
              axios.post('/auditreply/saveOrUpdateM', {
                Save: type,
                AuditReplyLists:JSON.stringify(AuditReplyLists),
                ProjectId: this.$route.query.ProjectId,
                Atype: this.$route.query.Atype,
                Aoc: '2',
                Save: type
              }).then(res => {
                // 发送成功后跳转到正在审核页面
                this.$router.push({name: "myProjectCheck"})
              }).catch(err => {
                this.$Modal.error({
                  title: '发送失败'
                })
              })
            } else {
              this.$Modal.error({
                title: title 
              })
            }
          })
        }else{
          console.log('别点了老铁')
        }
      },
      upWord(url){        //分割字符串
      if(url == null){
        return '上传'
      }else{
        var upWord = url;
        upWord = upWord.split("/");
        upWord = upWord.slice(-1);
        upWord = upWord.join('');
        // console.log(upWord)
        return upWord
      }
    }
    },
  }
</script>

<style lang="less" scoped>
  #fushen {
    .ivu-input {
      border: none !important;
      height: 30px;

      input {
        outline: medium;
      }
    }

    .ivu-table-tip {
      overflow-x: hidden;
    }
  }
  /deep/ textarea.ivu-input {
    font-size: 12px;
  }
  .sizeStyle {
    font-size:12px;
  }
</style>